﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace RelyingParty
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.User.Identity.IsAuthenticated)
                return;

            ClaimsPrincipal claimsPrincipal = Page.User as ClaimsPrincipal;

            // The code below shows claims found in the IClaimsIdentity.

            Table claimsTable = new Table();
            TableRow headerRow = new TableRow();

            TableCell claimTypeCell = new TableCell();
            claimTypeCell.Text = "Claim Type";
            claimTypeCell.BorderStyle = BorderStyle.Solid;

            TableCell claimValueCell = new TableCell();
            claimValueCell.Text = "Claim Value";
            claimValueCell.BorderStyle = BorderStyle.Solid;

            headerRow.Cells.Add(claimTypeCell);
            headerRow.Cells.Add(claimValueCell);
            claimsTable.Rows.Add(headerRow);

            TableRow newRow;
            TableCell newClaimTypeCell, newClaimValueCell;
            foreach (Claim claim in claimsPrincipal.Claims)
            {
                newRow = new TableRow();
                newClaimTypeCell = new TableCell();
                newClaimTypeCell.Text = claim.Type.ToString();

                newClaimValueCell = new TableCell();
                newClaimValueCell.Text = claim.Value;

                newRow.Cells.Add(newClaimTypeCell);
                newRow.Cells.Add(newClaimValueCell);

                claimsTable.Rows.Add(newRow);
            }

            Controls.Add(claimsTable);
        }
    }
}